package com.tianma.upload.uploadjartest.proxy.dynamicProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.List;

/**
 * @author lgc
 * @createDate 2020/8/13 - 15:09
 */
public class ProxyUtils<T>{
    private T t;
    public ProxyUtils(T t) {
        this.t = t;
    }

    public T getProxyObjct(){
        return (T) Proxy.newProxyInstance(this.getClass().getClassLoader(), t.getClass().getInterfaces(),
                (proxy,method,args)->{
                    String methodName = method.getName();
                    System.out.println("代理类执行了"+methodName+"方法");
                      if (method.getName().equals("lookHome")){
                        String str = (String) args[0];
                        str="["+str+"]";
                        return method.invoke(t,str);
                       }
                        return method.invoke(t,args);}
        );
    }
}
